Repository navigation
feat(storage): add StorageErrorTypeMapper for standard metrics - #14694
nidhiii-27 wants to merge 1 commit into
Conversation
a1393ca to
41c47ff
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive support for OpenTelemetry client metrics and debug metrics in Google Cloud Storage, including configuration options in StorageOptions, GrpcStorageOptions, and HttpStorageOptions. It adds utility classes such as StorageClientMetrics for instrument registration, StorageErrorTypeMapper for mapping exceptions to canonical error strings, StorageMetricsConfig for environment-based configuration, and StorageMetricsContext for tracking metric state across boundaries, along with corresponding unit tests. Feedback on the changes suggests simplifying a redundant null check on a transient field in StorageOptions, defensively preventing infinite loops from self-causation in StorageErrorTypeMapper's exception unwrapping, and robustly checking for authentication exceptions by using full class names instead of simple names to correctly handle anonymous classes.
I am having trouble creating individual review comments. Click here to see my feedback.
java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageOptions.java (262)
Since meterProvider is marked as transient, it will not be serialized and will always be null after deserialization. Therefore, the check this.meterProvider != null in readObject is redundant and will always evaluate to false. We can simplify this to only check this.customMeterProviderConfigured.
if (this.customMeterProviderConfigured) {
java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageErrorTypeMapper.java (159-162)
To prevent potential infinite loops in case of custom exceptions with self-causation (where t.getCause() == t), we should defensively add a check for t.getCause() != t in the while loop condition, similar to how it is handled at the end of the mapThrowable method.
while ((t instanceof ExecutionException || t instanceof CompletionException)
&& t.getCause() != null
&& t.getCause() != t) {
t = t.getCause();
}
java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageErrorTypeMapper.java (258)
Using t.getClass().getSimpleName() can return an empty string "" for anonymous classes, which would bypass the contains("Auth") check even if the base class name contains "Auth". Using the full class name className.contains("Auth") is more robust and avoids extra string parsing overhead.
if (className.contains("Auth")) {
608c46a to
1bf9a9d
Compare
- Map HTTP 401 to UNAUTHENTICATED and HTTP 502 to UNAVAILABLE. - Guard against self-causation cycles in ExecutionException/CompletionException loops. - Check hasSpecificClientCause on StatusRuntimeException, StatusException, and ApiException before status code mapping. - Support cause unwrapping for gRPC exceptions on StorageException. - Add unit tests for gRPC network causes and self-referencing exceptions. [Generated-by: AI]
6374b3e to
98fb508
Compare
98fb508 to
84a5ac6
Compare
84a5ac6 to
ed62afa
Compare
Adds mapping logic to classify exceptions and HTTP status codes into standard OpenTelemetry error types.
StorageErrorTypeMapperfor error.type and rpc status code classification.StorageErrorTypeMapperTest.Stacked on #14484.